<?php
/**
* Used to redirect from a page_ident to the normal username\page\page name
*   Needed to provide a permanent url to a page, as the name can change.
*
* @package folio
* @param int $page_ident The page_ident being shown.
*/

    define("context", "folio_page_view");
    // Run includes
    require("../../../includes.php");
    require_once("../model/page.php");
    require_once("../model/user.php");

    global $CFG;
    global $PAGE;
    global $FOLIO_CFG;

    // Retrieve passed variables 
    $page_ident = intval( required_param('page_ident') );

    // Load Page information
    $page = folio_page::SelectWherePageIdent( $page_ident );

    if( !$page ) {
        // Invalid page ident passed.
        echo 'Invalid page ident ' . $page_ident . ' passed to page_redirection.php';

    } else {
        // Existing page, no permission.
        $user = folio_user::SelectWhereIdent( $page->user_ident );

        header("Location: " . url . $user->username . '/page/' . folio_page::title_encode($page->title) );

        $body = false;

    }

?>